<?php
class Core_Model_Ability
	extends Core_Model_Abstract
{
	const STR	= 'Strength';
	const DEX	= 'Dexitry';
	const CON	= 'Constitution';
	const INT	= 'Intelligence';
	const WIS	= 'Wisdom';
	const CHA	= 'Charisma';
	
	protected $_type;
	
	public static function getAbilities()
	{
		return array('STR'	=> self::STR,
					'DEX'	=> self::DEX,
					'CON'	=> self::CON,
					'INT'	=> self::INT,
					'WIS'	=> self::WIS,
					'CHA'	=> self::CHA);
	}
	
	public static function calcMod($score)
	{
		if ($score < 1)
		{
			throw new Core_Model_Ability_Exception('Score too Low');
		}
		
		if ($score >= 10)
		{
			return floor(($score - 10) / 2);	
		}

		if ($score < 10)
		{
			return ceil(($score - 10) / 2);		
		}		
	}
	
	public static function validAbility($type)
	{
		if (array_key_exists(strtoupper($type), self::getAbilities()))
		{
			return strtoupper($type);
		}
		
		$search	= array_search($type, self::getAbilities());
		
		if ($search !== false)
		{
			return $search;
		}
		
		return false;
	}
	
	public function setType($type)
	{
		$type	= $this->validAbility($type);
		
		if (false === $type)
		{
			throw new Core_Model_Ability_Exception('Invalid Type');
		}
		
		return $this->_type	= $type;
	}
	
	public function getType()
	{
		return $this->_type;
	}
}